﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ClassWeb.App_Data;
using System.Text;

using ClassModel;
using ClassCommon;
using ClassBLL;


namespace ClassWeb.Controllers
{
    public class ScheduleClassController : BaseController
    {
        //
        // GET: /ScheduleClass/

        /// <summary>
        /// 排课首页 --> login-first.html
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {

            ViewBag.CurrentUser = this.CurrentUser;

            if (this.CurrentUser == null)
                // 没有登录回到主页
                return Redirect("/home");


            var list = t_class_task_BLL.List(this.CurrentUser.id, 0, 10);
            if (list != null) return Redirect("ArrangeTaskList");

            return View();
        }

        #region unuseView

        /// <summary>
        /// 自动排课  --> 自动排课.html
        /// </summary>
        /// <returns></returns>
        public ActionResult AutoScheduleClass()
        {
            return View();
        }


        /// <summary>
        /// 规则条件.html
        /// </summary>
        /// <returns></returns>
        public ActionResult ClassRule()
        {
            return View();
        }


        /// <summary>
        /// 预排.html
        /// </summary>
        /// <returns></returns>
        public ActionResult PrepareListClass()
        {
            return View();
        }
        /// <summary>
        /// 不连堂 ----> 不连堂.html
        /// </summary>
        /// <returns></returns>
        public ActionResult NoContinuous()
        {
            return View();
        }


        /// <summary>
        /// 其他-周任课分布 .html
        /// </summary>
        /// <returns></returns>
        public ActionResult WeekClassConfig()
        {
            return View();
        }


        /// <summary>
        /// 其他-日任课分布.html
        /// </summary>
        /// <returns></returns>
        public ActionResult DailyClassConfig()
        {
            return View();
        }

        /// <summary>
        /// 其他-时段分布.html
        /// </summary>
        /// <returns></returns>
        public ActionResult TimelyClassConfig()
        {
            return View();
        }

        /// <summary>
        /// 其他-连上限制.html
        /// </summary>
        /// <returns></returns>
        public ActionResult ContinusLimitConfig()
        {
            return View();
        }


        /// <summary>
        /// 其他.html
        /// </summary>
        /// <returns></returns>
        public ActionResult OtherClassConfig()
        {

            return View();
        }
        #endregion

        #region 合班相关
        /// <summary>
        /// 合班.html
        /// </summary>
        /// <returns></returns>
        public ActionResult MergeClassConfig(string taskid)
        {
            #region 服务器端判断
            if (string.IsNullOrEmpty(taskid)) return Redirect("/home");
            if (this.CurrentUser == null) return Redirect("/home");
            #endregion

            int decodeTaskId = 0;
            try
            {
                decodeTaskId = Convert.ToInt32(EncryptHelper.Decrypt(taskid));
            }
            catch (Exception)
            {
                return Redirect("/Home");
                throw;
            }

            ViewBag.RawTaskId = taskid;
            ViewBag.decodeTaskId = decodeTaskId;
            ViewBag.CurrentUser = this.CurrentUser;

            // 找到任务对应的上传文件对象
            t_class_fileupload fileupload = t_class_user_fileupalod_BLL.GetExcelFileWithTaskId(decodeTaskId, this.CurrentUser.id);
            if (fileupload == null) return Redirect("/home");

            ViewBag.fileid = fileupload.id; // 文件id

            var courseList = t_class_course_BLL.GetCourseListWithFileID(fileupload.id);

            ViewBag.courseList = courseList;


            return View();
        }



        /// <summary>
        /// 根据班级id获得老师和课程信息
        /// </summary>
        /// <param name="classid"></param>
        /// <param name="fileid"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetTeacherCourseInfo(int classid, int fileid)
        {
            this.Response.ContentType = "application/json";

            #region 服务器验证
            if (this.CurrentUser == null) return Redirect("/home");
            #endregion

            var list = t_class_schedule_BLL.GetTeacherAndCourseInfo(classid, fileid);

            // 获得年级信息
            t_class_grade grade = t_class_grade_BLL.GetGradeInfoWithFileId(fileid);

            return Json(new { status = list != null ? true : false, grade = grade.gradename, list = list }, JsonRequestBehavior.AllowGet);
        }


        /// <summary>
        /// 获得老师和班级的编码API
        /// </summary>
        /// <param name="courseid"></param>
        /// <param name="fileid"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetTeacherClassInfo(int courseid, int fileid)
        {
            this.Response.ContentType = "application/json";

            #region 服务器端验证
            if (this.CurrentUser == null) return Redirect("/home"); // wei denglu 
            #endregion

            List<t_class_Schedule_Bind> list = t_class_schedule_BLL.GetTeacherAndClassInfo(courseid, fileid);

            // 
            var mergeInfo = t_class_merge_BLL.GetMergeInfoByCourseId(courseid);
            if (mergeInfo != null)
            {
                var mergedClassids = mergeInfo.classIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();

                // List<t_class_Schedule_Bind> waitToMoveList = new List<t_class_Schedule_Bind>();

                for (int i = 0; i < list.Count; i++)
                {
                    var current = list[i];
                    if (mergedClassids.Contains(current.classid.ToString()))
                    {
                        list.Remove(current);
                        i--;
                    }
                }
            }


            //list.ForEach(schedule => {
            //    if (mergedClassids.Contains(schedule.classid.ToString())) {
            //        // waitToMoveList.Add(schedule);
            //        list.Remove(schedule);
            //    }
            //});



            // 获得年级信息
            t_class_grade grade = t_class_grade_BLL.GetGradeInfoWithFileId(fileid);

            return Json(new { status = list != null ? true : false, grade = grade.gradename, list = list }, JsonRequestBehavior.AllowGet);
        }


        /// <summary>
        /// 保存用户合班信息
        /// </summary>
        /// <param name="courseid"></param>
        /// <param name="classCount"></param>
        /// <param name="classids"></param>
        /// <param name="taskid"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SaveMergeInfo(
            int courseid, // 班级id
            int classCount, // 合班的个数
            string classids, // 合班的班级编号
            string teacherids, // 合班的老师编号
            string taskid // 任务编号
            )
        {
            this.Response.ContentType = "application/json";

            #region 服务端验证
            if (this.CurrentUser == null) return Redirect("/home");
            if (string.IsNullOrEmpty(taskid)) return Redirect("/home"); // 缺少必要参数!
            #endregion
            int decodeTaskid;
            try
            {
                decodeTaskid = Convert.ToInt32(EncryptHelper.Decrypt(taskid));
            }
            catch (Exception)
            {
                return Redirect("/home"); // 任务id的参数格式错误!
                throw;
            }

            t_class_merge merge = new t_class_merge();
            merge.taskid = decodeTaskid;
            merge.classCount = classCount;
            merge.classIds = classids;
            merge.courseid = courseid;
            merge.teacherIds = teacherids;
            merge.createtime = DateTime.Now;


            var result = t_class_merge_BLL.InsertClassMerge(merge);

            return Json(new { status = result }, JsonRequestBehavior.AllowGet);
        }


        /// <summary>
        /// 获得合班信息
        /// </summary>
        /// <param name="taskid"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetMergeInfoWithTaskId(string taskid)
        {
            this.Response.ContentType = "application/json";

            #region 服务端验证
            if (this.CurrentUser == null) return Redirect("/home"); // 未登录
            if (string.IsNullOrEmpty(taskid)) return Redirect("/home"); // 参数错误!
            #endregion

            int decodeTaskId = 0;

            try
            {
                decodeTaskId = Convert.ToInt32(EncryptHelper.Decrypt(taskid));
            }
            catch (Exception)
            {
                return Redirect("/home"); // 参数格式错误!
                throw;
            }


            var mergeInfoList = t_class_merge_BLL.GetMergeListWithTaskId(decodeTaskId);

            return Json(new { mergeList = mergeInfoList }, JsonRequestBehavior.AllowGet);
        }


        /// <summary>
        /// 删除合班信息 ---> 拆分合班
        /// </summary>
        /// <param name="taskid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult DeleteMergeInfo(string taskid, int id)
        {
            this.Response.ContentType = "application/json";

            #region 服务端验证
            if (this.CurrentUser == null) return Redirect("/home");
            if (string.IsNullOrEmpty(taskid)) return Redirect("/home");
            #endregion

            int decodeTaskId = 0;
            try
            {
                decodeTaskId = Convert.ToInt32(EncryptHelper.Decrypt(taskid));
            }
            catch (Exception)
            {
                return Redirect("/home");//参数格式错误!
                throw;
            }

            int result = t_class_merge_BLL.DeleteMergeInfo(decodeTaskId, id);

            return Json(new { status = result > 0 }, JsonRequestBehavior.AllowGet);
        }

        #endregion


        /// <summary>
        /// 排课任务列表  点击添加排课之后的html.html
        /// </summary>
        /// <returns></returns>
        public ActionResult ArrangeTaskList()
        {

            int userid = HttpCookieHelper.GetUserID();
            if (userid == -1) return Redirect("/Home");


            ViewBag.CurrentUser = this.CurrentUser;
            ViewBag.UserId = userid;

            return View();
        }

        /// <summary>
        /// 点击排课 “操作” 按钮之后显示的页面 ---> 添加排课名称之后的 HTML.html
        /// </summary>
        /// <returns></returns>
        public ActionResult OperatorClassDetail(string id)
        {
            if (this.CurrentUser == null) return Redirect("/Home");

            int detaskId = Convert.ToInt32(EncryptHelper.Decrypt(id.ToString()));

            t_class_task task = t_class_task_BLL.GetTaskById(detaskId, this.CurrentUser.id);
            if (task == null) return Redirect("/home");

            ViewBag.CurrentUser = this.CurrentUser;
            ViewBag.taskId = id; // 未解密之前的taskid

            ViewBag.Task = task;

            return View();
        }




        #region 用户附加信息 - 就是首页的那个弹窗
        /// <summary>
        /// 添加用户附加信息
        /// </summary>
        /// <param name="schoolName"></param>
        /// <param name="qqNumber"></param>
        /// <param name="area"></param>
        /// <param name="phone"></param>
        /// <param name="schoolType"></param>
        /// <param name="jobType"></param>
        /// <param name="ageArrange"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public ActionResult AddAttachment(
            string schoolName,
            string qqNumber,
            string area,
            string phone,
            string schoolType,
            string jobType,
            string ageArrange,
            string email
            )
        {


            /**
                schoolName: 开发区一中
                qqNumber: 2132132321
                area: 安徽省-芜湖市-弋江区
                phone: 18571656598
                schoolType: 2
                jobType: 0
                ageArrange: 1
                email: ddddd@163.com
             */
            this.Response.ContentType = "application/json";

            if (this.CurrentUser == null) return Redirect("/Home");

            //服务器端验证

            t_class_attachment_info attachment = new t_class_attachment_info();
            attachment.userID = this.CurrentUser.id;
            attachment.SchoolName = schoolName; // schoolName: 开发区一中
            attachment.QQ = qqNumber; // qqNumber: 2132132321
            attachment.Address = area; // area: 安徽省-芜湖市-弋江区
            attachment.PhoneNum = phone; // phone: 18571656598
            attachment.Duty = jobType; //  jobType: 0
            attachment.AgeRange = ageArrange; // ageArrange: 1
            attachment.Email = email; //  email: ddddd@163.com
            attachment.SchoolType = schoolType; // schoolType: 2
            attachment.createTime = DateTime.Now;

            int resultID = t_class_attachment_info_BLL.InsertAttachment(attachment);

            return Json(new { status = resultID });
        }
        #endregion

        #region 排课任务API
        /// <summary>
        /// 添加排课任务
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult AddClassTask(string name)
        {
            this.Response.ContentType = "application/json";
            // 服务端验证。

            int userid = HttpCookieHelper.GetUserID();
            if (userid == -1) return Json(new { status = false });

            // 没有设置学校信息暂时先无法排课。
            t_class_attachment_info info = t_class_attachment_info_BLL.GetAttachmentByUserId(userid);
            if (info == null) return Json(new { status = false });

            t_class_task task = new t_class_task();
            task.Name = name;
            task.Type = "常规";
            task.Status = "未排课";
            task.CreateTime = DateTime.Now;
            task.School = info.SchoolName;
            task.UserId = userid;

            int increaseID = t_class_task_BLL.insertTask(task);

            return Json(new { status = true, increaseID = increaseID }, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 删除排课任务
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult RemoveTaskByID(int id)
        {
            this.Response.ContentType = "application/json";

            if (this.CurrentUser == null) return Json(new { status = false }, JsonRequestBehavior.AllowGet);

            int reslt = t_class_task_BLL.DeleteById(id, this.CurrentUser.id);

            return Json(new { status = reslt > 0 ? true : false }, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 节次相关API
        /// <summary>
        /// 插入excel文件对应的上课节次设置
        /// </summary>
        /// <param name="fileid">文件id</param>
        /// <param name="dayofweek">一周上几天课</param>
        /// <param name="amSections">上午节次</param>
        /// <param name="pmSections">下午节次</param>
        /// <param name="evSections">晚自习节次</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SettingSection(
            string taskid,
            int dayofweek,
            int amSections,
            int pmSections,
            int evSections = 0
            )
        {

            /**
             taskid: 7BF56BD9A6AFEA21
dayofweek: 5
amSections: 4
pmSections: 3
             */
            this.Response.ContentType = "application/json";

            #region 验证相关
            // 登录验证
            if (this.CurrentUser == null) return Json(new { status = false, info = "您还未登录，请登录后操作。" }, JsonRequestBehavior.AllowGet);

            // 服务端验证。 dayofweek <= 7 节次不能为负数
            // if (...

            // excel - fileid 验证
            string decodeTaskId = EncryptHelper.Decrypt(taskid);
            int intTaskId = Convert.ToInt32(decodeTaskId);
            if (!t_class_user_fileupalod_BLL.theFileIsCurrentLoginerWith(intTaskId, this.CurrentUser.id))
                return Json(new { status = false, info = "请选上传需要的课程excel模板文件" }, JsonRequestBehavior.AllowGet);
            #endregion

            #region 添加节次model

            t_class_fileupload fileupload = t_class_user_fileupalod_BLL.GetExcelFileWithTaskId(intTaskId, this.CurrentUser.id);

            t_class_sections sections = new t_class_sections();
            sections.taskid = intTaskId;
            sections.AMSections = amSections;
            sections.PMSections = pmSections;
            sections.EVSections = evSections;
            sections.dayOfWeek = dayofweek;
            sections.fileid = fileupload.id;

            #endregion

            int increaseId = t_class_sections_BLL.InsertSections(sections);

            string tip = increaseId > 0 ? "操作成功" : "操作失败";


            return Json(new
            {
                status = increaseId > 0,
                info = tip,
                info2 = increaseId == -2 ? "excel表格一周课程数据和节次设置的不一致!" : string.Empty
            },
                JsonRequestBehavior.AllowGet);
        }


        /// <summary>
        /// 检查节次设置
        /// </summary>
        /// <param name="taskid"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult CheckSectionIsExist(string taskid)
        {
            this.Response.ContentType = "application/json";

            #region 服务端验证
            if (this.CurrentUser == null) return Json(new { status = false, info = "请先登录，在进行此操作" }, JsonRequestBehavior.AllowGet);
            if (string.IsNullOrEmpty(taskid)) return Json(new { status = false, info = "参数错误!" }, JsonRequestBehavior.AllowGet);

            #endregion

            string deCodeFileId = EncryptHelper.Decrypt(taskid);

            bool result = t_class_sections_BLL.CheckExistWithFileID(Convert.ToInt32(deCodeFileId));

            return Json(new { status = result }, JsonRequestBehavior.AllowGet);
        }

        #endregion

        #region 规则条件API
        /// <summary>
        /// 规则条件
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult RuleIndex(string taskid)
        {
            if (this.CurrentUser == null) return Redirect("/home");
            int decodeTaskid = 0;
            try
            {
                decodeTaskid = Convert.ToInt32(EncryptHelper.Decrypt(taskid));
            }
            catch (Exception ex)
            {
                return Redirect("/Home");
                throw;
            }

            ViewBag.CurrentUser = this.CurrentUser;
            ViewBag.Taskid = taskid;
            ViewBag.decodeTaskid = decodeTaskid;

            return View();
        }
        #endregion

        #region 不排课相关API
        /// <summary>
        /// 获取不排课页面，老师和课程的数据
        /// </summary>
        /// <param name="taskid"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult TeacherAndClassApi(string taskid, int pageIndex)
        {
            this.Response.ContentType = "application/json";

            #region 服务端验证
            if (this.CurrentUser == null) return Json(new { status = false, info = "还未登录，无法进行此操作!" }, JsonRequestBehavior.AllowGet);
            #endregion

            int decodeTaskId = 0;
            try
            {
                decodeTaskId = Convert.ToInt32(EncryptHelper.Decrypt(taskid));
            }
            catch (Exception)
            {
                return Json(new { status = false, info = "参悟有误，无法进行此操作!" }, JsonRequestBehavior.AllowGet);
                throw;
            }

            int count;
            var fileupload = t_class_user_fileupalod_BLL.GetExcelFileWithTaskId(decodeTaskId, this.CurrentUser.id);
            var list = t_class_teacher_BLL.GetTeachersInfoWhitFileId(fileupload.id, out count, pageIndex);

            return Json(new { status = true, list = list, currentPage = pageIndex, totalCount = count }, JsonRequestBehavior.AllowGet);
        }


        /// <summary>
        /// 获取不排课数据
        /// </summary>
        /// <param name="taskid">任务id</param>
        /// <param name="classPostData">班级不排课数据</param>
        /// <param name="teacherPostData">老师不排课数据</param>
        /// <param name="coursePostData">课程不排课数据</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult getScheduleData(
            string taskid, // 任务id
            string classPostData, // 班级不排课数据
            string teacherPostData, // 老师不排课数据
            string coursePostData // 课程不排课数据
            )
        {
            /*
taskid: 47112912FC36852A
classPostData: 1|1_1_0,2_1_0,3_1_0&6|1_2_0,2_2_0,3_2_0&7|1_3_0,2_3_0,3_3_0&
teacherPostData: 1|1_1_0,1_2_0,1_3_0&5|7_3_0,7_4_0,7_5_0&
coursePostData: 1|1_2_0,2_2_0,2_3_0&4|2_3_0,3_3_0,3_2_0&6|4_4_0,3_4_0,2_4_0&
             */

            this.Response.ContentType = "application/json";

            #region 服务器端验证
            if (string.IsNullOrEmpty(taskid)) return Json(new { status = false, info = "重要参数缺失!" }, JsonRequestBehavior.AllowGet);

            int decodeTaskid = 0;
            try
            {
                decodeTaskid = Convert.ToInt32(EncryptHelper.Decrypt(taskid));
            }
            catch (Exception)
            {
                return Json(new { status = false, info = "参数解析错误!" }, JsonRequestBehavior.AllowGet);
                throw;
            }
            #endregion

            List<t_ClassTeacherCourse_NoSchedule> list = new List<t_ClassTeacherCourse_NoSchedule>();

            #region 各种不排课数据转模型
            // 班级不排课
            if (!string.IsNullOrEmpty(classPostData))
            {
                var clsList = GetPostData(classPostData, ConfigSetting.NoScheduleClassType, decodeTaskid);
                if (clsList != null)
                {
                    list.AddRange(clsList);
                }
            }

            // 课程不排课
            if (!string.IsNullOrEmpty(coursePostData))
            {
                var corList = GetPostData(coursePostData, ConfigSetting.NoScheduleCourseType, decodeTaskid);
                if (corList != null)
                {
                    list.AddRange(corList);
                }
            }

            // 老师不排课
            if (!string.IsNullOrEmpty(teacherPostData))
            {
                var teaList = GetPostData(teacherPostData, ConfigSetting.NoScheduleTeacher, decodeTaskid);
                if (teaList != null)
                {
                    list.AddRange(teaList);
                }
            }
            #endregion

            if (list.Count > 0)
            {
                for (int l = 0; l < list.Count; l++)
                {
                    t_ClassTeacherCourse_NoSchedule_BLL.InsertNoScheduleData(list[l]);
                }
            }


            return Json(new { status = true, info = "不排课数据存储成功!" }, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 数据格式转换
        /// </summary>
        /// <param name="data">任务字符串 id|1_1_0,1_2_0&22|3_9_0.....</param>
        /// <param name="dataId">标记id</param>
        /// <param name="outData">不排课字符串</param>
        private List<t_ClassTeacherCourse_NoSchedule> GetPostData(string postData, string type, int taskid)
        {

            /**
             taskid: 47112912FC36852A
             classPostData: 1|1_1_0,2_1_0,3_1_0&6|1_2_0,2_2_0,3_2_0&7|1_3_0,2_3_0,3_3_0&
             teacherPostData: 1|1_1_0,1_2_0,1_3_0&5|7_3_0,7_4_0,7_5_0&
             coursePostData: 1|1_2_0,2_2_0,2_3_0&4|2_3_0,3_3_0,3_2_0&6|4_4_0,3_4_0,2_4_0&
             */

            if (string.IsNullOrEmpty(postData)) return null;

            List<t_ClassTeacherCourse_NoSchedule> list = new List<t_ClassTeacherCourse_NoSchedule>();

            string[] bigArray = postData.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);

            for (int b = 0; b < bigArray.Length; b++)
            {
                string single = bigArray[b];
                string[] smallArray = single.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                int dataid = Convert.ToInt32(smallArray[0]);
                string data = smallArray[1];

                t_ClassTeacherCourse_NoSchedule noSchedule = new t_ClassTeacherCourse_NoSchedule();
                noSchedule.data = data;
                noSchedule.dataid = dataid;
                noSchedule.createtime = DateTime.Now;
                noSchedule.taskid = taskid;
                noSchedule.type = type;

                list.Add(noSchedule);
            }

            return list;
        }


        /// <summary>
        /// 获取不排课的数据(分别是老师、课程、班级)
        /// </summary>
        /// <param name="taskid">任务id</param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult getNoScheduleList(string taskid)
        {
            this.Response.ContentType = "application/json";
            #region 服务端验证
            if (this.CurrentUser == null) return Redirect("/home");
            if (string.IsNullOrEmpty(taskid)) return Redirect("/home");//缺少参数
            #endregion
            int decodeTaskId = 0;
            try
            {
                decodeTaskId = Convert.ToInt32(EncryptHelper.Decrypt(taskid));
            }
            catch (Exception)
            {
                return Redirect("/home"); // 参数错误!
                throw;
            }

            var noScheduleList = t_ClassTeacherCourse_NoSchedule_BLL.GetTeacherClassCourseNoScheduleList(decodeTaskId);

            var classNoScheduleList = noScheduleList.Where(s => s.type == "class").ToList();
            var courseNoScheduleList = noScheduleList.Where(s => s.type == "course").ToList();
            var teacherNoScheduleList = noScheduleList.Where(s => s.type == "teacher").ToList();


            return Json(new
            {
                classList = classNoScheduleList,
                courseList = courseNoScheduleList,
                teacherList = teacherNoScheduleList
            },
                JsonRequestBehavior.AllowGet);
        }


        #endregion

        #region 老师、班级获取数据相关的API

        /// <summary>
        /// 主要是用于合班的HTML页面老师数据恢复是否，使用范围很窄。
        /// </summary>
        /// <param name="teacherIds"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetTeachersInfoWithTeacherIds(string teacherIds)
        {
            this.Response.ContentType = "application/json";
            #region 服务端验证
            if (this.CurrentUser == null) return Redirect("/home");
            if (string.IsNullOrEmpty(teacherIds)) return Redirect("/home");
            #endregion
            var teaIdsList = teacherIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            string teacherNames = string.Empty;
            teaIdsList.ForEach(id =>
            {
                teacherNames += t_class_teacher_BLL.GetTeacherInfoById(Convert.ToInt32(id)).teacher + ",";
            });


            teacherNames = teacherNames.TrimEnd(new char[] { ',' });

            return Json(new { result = teacherNames }, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 主要是用于合班的HTML页面班级数据恢复是否，使用范围很窄。
        /// </summary>
        /// <param name="classIds"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetClassInfoWithClassIds(string classIds)
        {
            this.Response.ContentType = "application/json";

            #region 服务端验证
            if (this.CurrentUser == null) return Redirect("/home");
            if (string.IsNullOrEmpty(classIds)) return Redirect("/home");
            #endregion

            var classIdsList = classIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            string classNames = string.Empty;
            classIdsList.ForEach(clsId =>
            {
                classNames += t_class_classes_BLL.GetClassInfoById(Convert.ToInt32(clsId)).classname + ",";
            });

            classNames = classNames.TrimEnd(new char[] { ',' });

            return Json(new { result = classNames }, JsonRequestBehavior.AllowGet);
        }

        #endregion


        #region 开始排课
        public ActionResult BeginSchedule(string taskid)
        {
            if (this.CurrentUser == null) return Redirect("/home");
            if (string.IsNullOrEmpty(taskid)) return Redirect("/home");

            ViewBag.CurrentUser = this.CurrentUser;
            ViewBag.taskid = taskid;

            return View();
        }

        /// <summary>
        /// 开始排课
        /// </summary>
        /// <param name="taskid"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult CreateDataTxt(string taskid)
        {
            this.Response.ContentType = "application/json";
            #region 服务端验证
            if (this.CurrentUser == null) return Redirect("/home");
            if (string.IsNullOrEmpty(taskid)) return Redirect("/home");
            #endregion

            int decodeTaskId = 0;
            try
            {
                decodeTaskId = Convert.ToInt32(EncryptHelper.Decrypt(taskid));
            }
            catch (Exception)
            {
                return Redirect("/home");
                throw;
            }

            string dataTxt = t_class_CreateTxt_BLL.createDataTxt(decodeTaskId, this.CurrentUser.id);

            return Json(new { txt = dataTxt, status = true }, JsonRequestBehavior.AllowGet);

        }

        #endregion

    }
}
